import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_youren/widget/RotaTranPageState.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:fluttertoast/fluttertoast.dart';

class LoginPage extends StatelessWidget {
  const LoginPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      width: MediaQuery.of(context).size.width, // 屏幕宽度
      height: MediaQuery.of(context).size.height, // 屏幕高度
      decoration: const BoxDecoration(
        image: DecorationImage(
          fit: BoxFit.cover,
          image: AssetImage('assets/images/login_bg.png'),
        ),
      ),
      child: SingleChildScrollView(
        child: Container(
          margin: const EdgeInsets.only(top: 165),
          child: const LoginStatePage(),
        ),
      ),
    ));
  }
}

class LoginStatePage extends StatefulWidget {
  const LoginStatePage({super.key});

  @override
  State<LoginStatePage> createState() => _LoginStatePageState();
}

class _LoginStatePageState extends State<LoginStatePage> {
  bool _showPassword = false;

//改变显示/隐藏状态
  void _togglevisibility() {
    setState(() {
      _showPassword = !_showPassword;
    });
  }

  void _showPopWindow(bool isShow) {
    /// call directly https://www.jianshu.com/p/41e7852989dc?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
    /// windowHeigh = 200;

    // PopupWindowButton(
    //   offset: Offset(0, 200),
    //   buttonBuilder: (BuildContext context) {
    //     return PopupWindowBtn();
    //   },
    //   windowBuilder: (BuildContext context, Animation<double> animation,
    //       Animation<double> secondaryAnimation) {
    //     return FadeTransition(
    //       opacity: animation,
    //       child: SizeTransition(
    //         sizeFactor: animation,
    //         child: Container(
    //           color: Colors.greenAccent,
    //           height: 200,
    //         ),
    //       ),
    //     );
    //   },
    //   onWindowShow: () {
    //     print('PopupWindowButton window show');
    //   },
    //   onWindowDismiss: () {
    //     print('PopupWindowButton window dismiss');
    //   },
    // );

  //   PopupWindowButton(
  //     offset: Offset(0, 100),
  //     buttonBuilder: (BuildContext context) {
  //       return PopupWindowBtn();
  //     },
  //     windowBuilder: (BuildContext context, Animation<double> animation,
  //         Animation<double> secondaryAnimation) {
  //       return FadeTransition(
  //         opacity: animation,
  //         child: SizeTransition(
  //           sizeFactor: animation,
  //           child: Container(
  //             color: Colors.greenAccent,
  //             height: 100,
  //           ),
  //         ),
  //       );
  //     },
  //     onWindowShow: () {
  //       print('PopupWindowButton window show');
  //     },
  //     onWindowDismiss: () {
  //       print('PopupWindowButton window dismiss');
  //     },
  //   );
  }

  @override
  Widget build(BuildContext context) {
    final local = AppLocalizations.of(context);
    return Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: [
        Container(
          clipBehavior: Clip.hardEdge,
          decoration: BoxDecoration(borderRadius: BorderRadius.circular(10)),
          child: const Image(
              height: 57,
              width: 57,
              image: AssetImage('assets/images/logo.png')),
        ),
        const SizedBox(
          height: 10,
        ),
        const Text(
          'FlanklinWH',
          style: TextStyle(fontSize: 15, color: Colors.white),
        ),
        Container(
            height: 52,
            margin: const EdgeInsets.only(left: 28, right: 28, top: 49),
            decoration: const BoxDecoration(
              //背景
              color: Color(0xff2E4264),
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(26.0)),
              //设置四周边框
              //border:  Border.all(width: 1, color: Colors.red),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                const Expanded(
                  flex: 1,
                  child: Padding(
                    padding: EdgeInsets.only(left: 10),
                    child: TextField(
                      minLines: 1,
                      style: TextStyle(color: Color(0xffffffff), fontSize: 19),
                      decoration: InputDecoration(
                        fillColor: Colors.transparent,
                        //背景默认有一点颜色
                        border: InputBorder.none,
                        //去掉输入框下面的那条线
                        filled: true,
                        hintText: '请输入邮箱',
                        hintStyle:
                            TextStyle(color: Color(0xa9ffffff), fontSize: 19),
                      ),
                    ),
                  ),
                ),
                RotaTranPage(
                    key: null,
                    onPressed: (isShow) {
                      print('PopupWindowButton window show isShow');
                      _showPopWindow(isShow);
                    }),
              ],
            )),
        Container(
            height: 52,
            margin: const EdgeInsets.only(left: 28, right: 28, top: 10),
            decoration: const BoxDecoration(
              //背景
              color: Color(0xff2E4264),
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(26.0)),
              //设置四周边框
              //border:  Border.all(width: 1, color: Colors.red),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: Padding(
                    padding: const EdgeInsets.only(left: 10),
                    child: TextField(
                      minLines: 1,
                      obscureText: !_showPassword,
                      style: const TextStyle(
                          color: Color(0xffffffff), fontSize: 19),
                      decoration: const InputDecoration(
                        fillColor: Colors.transparent,
                        border: InputBorder.none,
                        filled: true,
                        hintText: '请输入密码',
                        hintStyle:
                            TextStyle(color: Color(0xa9ffffff), fontSize: 19),
                      ),
                    ),
                  ),
                ),
                IconButton(
                  padding: EdgeInsets.only(left: 8, right: 8),
                  color: Colors.white,
                  icon: Icon(
                      _showPassword ? Icons.visibility : Icons.visibility_off,
                      color: Colors.white,
                      size: 15.0),
                  onPressed: _togglevisibility,
                ),
              ],
            )),
        Container(
            height: 52,
            width: MediaQuery.of(context).size.width,
            margin: const EdgeInsets.only(left: 28, right: 28, top: 14),
            decoration: const BoxDecoration(
              //背景
              gradient: LinearGradient(
                  colors: [Color(0xff6491FF), Color(0xff3F73FF)]),
              borderRadius: BorderRadius.all(Radius.circular(26.0)), //设置四周圆角 角度
              //border:  Border.all(width: 1, color: Colors.red),//设置四周边框
            ),
            child: TextButton(
                onPressed: () {
                  Fluttertoast.showToast(
                      msg: "登录",
                      toastLength: Toast.LENGTH_SHORT,
                      gravity: ToastGravity.CENTER,
                      backgroundColor: Colors.white,
                      textColor: Colors.black,
                      fontSize: 15.0);
                },
                child: const Text(
                  '登陆',
                  style: TextStyle(fontSize: 15, color: Colors.white),
                ))),
        const SizedBox(
          height: 10,
        ),
        RichText(
          text: TextSpan(
              style: DefaultTextStyle.of(context).style,
              children: <InlineSpan>[
                TextSpan(
                    text: local?.register,
                    style: const TextStyle(color: Colors.white),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        Fluttertoast.showToast(
                            msg: "点击了注册",
                            toastLength: Toast.LENGTH_SHORT,
                            gravity: ToastGravity.CENTER,
                            timeInSecForIosWeb: 1,
                            backgroundColor: Colors.white,
                            textColor: Colors.black,
                            fontSize: 15.0);
                      }),
                const TextSpan(
                    text: ' | ', style: TextStyle(color: Colors.white)),
                TextSpan(
                    text: local?.forget_pws,
                    style: const TextStyle(color: Colors.white),
                    recognizer: TapGestureRecognizer()
                      ..onTap = () {
                        Fluttertoast.showToast(
                            msg: "点击了忘记密码",
                            toastLength: Toast.LENGTH_SHORT,
                            gravity: ToastGravity.CENTER,
                            timeInSecForIosWeb: 1,
                            backgroundColor: Colors.white,
                            textColor: Colors.black,
                            fontSize: 15.0);
                      }),
              ]),
        )
      ],
    );
  }
}

/// 图片旋转类
class RotaTranPage extends StatefulWidget {
  final UDPressCallBack? onPressed;

  const RotaTranPage({super.key, this.onPressed});

  @override
  State<RotaTranPage> createState() => RotaTranPageState(onPressed: onPressed);
}

class PopupWindowBtn extends StatefulWidget {
  const PopupWindowBtn({Key? key}) : super(key: key);

  @override
  State<PopupWindowBtn> createState() => _PopupWindowBtnState();
}

class _PopupWindowBtnState extends State<PopupWindowBtn> {
  @override
  Widget build(BuildContext context) {
    return Text(
      "Popwindow",
      style: TextStyle(color: Colors.white),
    );
  }
}
